package com.qingsong.controller;

import com.mybatisflex.core.paginate.Page;
import com.qingsong.dto.CategoryInsertDTO;
import com.qingsong.dto.CategoryPageDTO;
import com.qingsong.dto.CategoryUpdateDTO;
import com.qingsong.entity.Category;
import com.qingsong.vo.CategorySimpleListVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.qingsong.service.CategoryService;

import java.util.List;

/**
 * 类别表 控制层。
 *
 * @author qingsong
 * @since 2024-12-22
 */
@Tag(name = "类别")
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @Operation(summary = "新增-单条", description = "新增一条类别记录")
    @PostMapping("insert")
    public boolean insert(@Validated @RequestBody CategoryInsertDTO dto) {
        return categoryService.insert(dto);
    }

    @Operation(summary = "查询-单条", description = "按主键查询一条类别记录")
    @GetMapping("select/{id}")
    public Category select(@PathVariable("id") Long id) {
        return categoryService.select(id);
    }

    @Operation(summary = "查询-简单列表", description = "查询全部类别记录,仅返回简单信息")
    @GetMapping("simpleList")
    public List<CategorySimpleListVO> simpleList() {
        return categoryService.simpleList();
    }

    @Operation(summary = "查询-分页", description = "分页查询类别记录")
    @GetMapping("page")
    public Page<Category> page(@Validated CategoryPageDTO dto) {
        return categoryService.page(dto);
    }

    @Operation(summary = "修改-单条", description = "按主键修改一条类别记录")
    @PutMapping("update")
    public boolean update(@RequestBody CategoryUpdateDTO dto) {
        return categoryService.update(dto);
    }

    @Operation(summary = "删除-单条", description = "按主键删除一条类别记录")
    @DeleteMapping("delete/{id}")
    public boolean delete(@PathVariable("id") Long id) {
        return categoryService.delete(id);
    }

    @Operation(summary = "删除-批量", description = "按主键批量删除类别记录")
    @DeleteMapping("deleteBatch")
    public boolean deleteBatch(@RequestParam("ids") List<Long> ids) {
        return categoryService.deleteBatch(ids);
    }

}
